home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / BC_TI.ARJ / TI801.ASC < prev    next >
Text File  |  1992-02-25  |  1KB  |  67 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  C++                                    NUMBER  :  801
  9.   VERSION  :  All
  10.        OS  :  DOS
  11.      DATE  :  February 25, 1992                        PAGE  :  1/1
  12.  
  13.     TITLE  :  Defining and Using Arrays of Pointers to Functions
  14.  
  15.  
  16.  
  17.  
  18.   The following demonstrates how to define and initailize an array
  19.   of pointers to functions.  In addition, calling a function whose
  20.   pointer is contained in such an array is demonstrated.
  21.  
  22.   #include <stdio.h>
  23.  
  24.   void (*p[5])();            // p is defined to be an array of
  25.                              // 5 pointers to functions taking
  26.                              // no (void) paramaters and returning
  27.                              // nothing (void)
  28.  
  29.   void foo1(void) { printf("Hello, in function foo1\n"); }
  30.   void foo2(void) { printf("Hello, in function foo2\n"); }
  31.  
  32.   main()
  33.   {
  34.      p[0]=foo1;  // Assign pointer at array index 0
  35.                  // to point at function foo1.
  36.      p[0]();     // Now call foo1
  37.  
  38.  
  39.      p[1]=foo2;  // Assign pointer at array index 1
  40.                  // to point to function foo2.
  41.      p[1]();     // Now call foo2
  42.   }
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.